package com.ruoyi.web.controller.airplane;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.vo.TbDeviceInfoVO;
import com.ruoyi.system.domain.vo.TbDeviceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbDeviceDataPackages;
import com.ruoyi.system.service.ITbDeviceDataPackagesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备安装数据包信息Controller
 *
 * @author ruoyi
 * @date 2025-08-11
 */
@Api(tags = "设备安装数据包信息")
@RestController
@RequestMapping("/system/packages")
public class TbDeviceDataPackagesController extends BaseController {
    @Autowired
    private ITbDeviceDataPackagesService tbDeviceDataPackagesService;

    /**
     * 查询设备安装数据包信息列表
     */
    //@PreAuthorize("@ss.hasPermi('system:packages:list')")
    @ApiOperation("查询设备安装数据包信息列表")
    @GetMapping("/list")
    public TableDataInfo list(TbDeviceDataPackages tbDeviceDataPackages) {
        startPage();
        List<TbDeviceDataPackages> list = tbDeviceDataPackagesService.selectTbDeviceDataPackagesList(tbDeviceDataPackages);
        return getDataTable(list);
    }

    /**
     * 导出设备安装数据包信息列表
     */
    // @PreAuthorize("@ss.hasPermi('system:packages:export')")
    @Log(title = "设备安装数据包信息", businessType = BusinessType.EXPORT)
    @ApiOperation("导出设备安装数据包信息列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDeviceDataPackages tbDeviceDataPackages) {
        List<TbDeviceDataPackages> list = tbDeviceDataPackagesService.selectTbDeviceDataPackagesList(tbDeviceDataPackages);
        ExcelUtil<TbDeviceDataPackages> util = new ExcelUtil<TbDeviceDataPackages>(TbDeviceDataPackages.class);
        util.exportExcel(response, list, "设备安装数据包信息数据");
    }

    /**
     * 获取设备安装数据包信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:packages:query')")
    @ApiOperation("获取设备安装数据包信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tbDeviceDataPackagesService.selectTbDeviceDataPackagesById(id));
    }

    /**
     * 新增设备安装数据包信息
     */
    //  @PreAuthorize("@ss.hasPermi('system:packages:add')")
    @Log(title = "设备安装数据包信息", businessType = BusinessType.INSERT)
    @ApiOperation("新增设备安装数据包信息")
    @PostMapping
    public AjaxResult add(@RequestBody TbDeviceDataPackages tbDeviceDataPackages) {
        return toAjax(tbDeviceDataPackagesService.insertTbDeviceDataPackages(tbDeviceDataPackages));
    }

    /**
     * 修改设备安装数据包信息
     */
    //  @PreAuthorize("@ss.hasPermi('system:packages:edit')")
    @Log(title = "设备安装数据包信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改设备安装数据包信息")
    public AjaxResult edit(@RequestBody TbDeviceDataPackages tbDeviceDataPackages) {
        return toAjax(tbDeviceDataPackagesService.updateTbDeviceDataPackages(tbDeviceDataPackages));
    }

    /**
     * 删除设备安装数据包信息
     */
    //  @PreAuthorize("@ss.hasPermi('system:packages:remove')")
    @Log(title = "设备安装数据包信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除设备安装数据包信息")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbDeviceDataPackagesService.deleteTbDeviceDataPackagesByIds(ids));
    }


    @ApiOperation("对应版本的数据包关联的设备列表")
    @PostMapping("/rel/device/list")
    public TableDataInfo listDevices(@RequestBody TbDeviceDataPackages tbDeviceDataPackages) {
        startPage();
        List<TbDeviceVO> list = tbDeviceDataPackagesService.selectTbDevicesList(tbDeviceDataPackages);
        return  getDataTable( list);
    }

}
